﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_ReturnController : BaseApiController
    {
        #region DI

        public PB_ReturnController(IPB_ReturnBusiness pB_ReturnBus)
        {
            _pB_ReturnBus = pB_ReturnBus;
        }

        IPB_ReturnBusiness _pB_ReturnBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_Return>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_ReturnBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_Return> GetTheData(IdInputDTO input)
        {
            return await _pB_ReturnBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 回货单选择收货方
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_Department>> GetReturnDeptListData()
        {
            return await _pB_ReturnBus.GetReturnDeptListDataAsync();
        }

        /// <summary>
        /// 根据项目获取物料信息
        /// </summary>
        /// <param name="ProjectId">项目id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<ViewPB_ReturnDTO>> GetReturnListData(string ProjectId)
        {
            return await _pB_ReturnBus.GetReturnListDataAsync(ProjectId);
        }

        /// <summary>
        /// PDA根据项目获取物料信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<ViewPB_ReturnDTO>> GetPDAReturnListDataAsync(ReturnCondition data)
        {
            return await _pB_ReturnBus.GetPDAReturnListDataAsync(data);
        }

        /// <summary>
        /// 回货单保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveReturnData(PB_ReturnDTO data)
        {
            await _pB_ReturnBus.SaveReturnDataAsync(data);
        }

        /// <summary>
        /// 回货单审核
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task ToExamineReturnData(string id)
        {
            await _pB_ReturnBus.ToExamineReturnDataAsync(id);
        }


        /// <summary>
        /// 获取回货单list
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_ReturnListDTO>> GetDataListData(PageInput<ConditionDTO> input)
        {
            return await _pB_ReturnBus.GetDataListDataAsync(input);
        }

        /// <summary>
        /// 查看回货单详细信息
        /// </summary>
        /// <param name="Id">回货单Id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ReturnDataDTO> GetReturnData(string Id)
        {
            return await _pB_ReturnBus.GetReturnDataAsync(Id);
        }

        /// <summary>
        /// 查看回货单详细信息
        /// </summary>
        /// <param name="Qrcode">回货单二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ReturnDataDTO> GetReturnSortingDataQrcode(string Qrcode)
        {
            return await _pB_ReturnBus.GetReturnSortingData(Qrcode);
        }
        

        /// <summary>
        /// 获取回货单list
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_ReturnListDTO>> GetDataSortingListData(PageInput<ConditionDTO> input)
        {
            return await _pB_ReturnBus.GetDataSortingListDataAsync(input);
        }

        /// <summary>
        /// 回货单分拣保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveReturnSortingData(PB_ReturnSortingDataDTO data)
        {
            await _pB_ReturnBus.SaveReturnSortingDataAsync(data);
        }
        
        /// <summary>
        /// 回货分拣确认生成收货单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task AddReceivingDataAsync(PB_RevingAdd data) {
            await _pB_ReturnBus.AddReceivingDataAsync(data);
        }
        [HttpPost]
        public async Task AddBatchSorting(BatchSorting data) {
            await _pB_ReturnBus.AddBatchSorting(data);
        }
        /// <summary>
        /// 回货单分拣详细信息
        /// </summary>
        /// <param name="Id">回货单Id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_ReturnDataDTO> GetReturnSortingData(string Id)
        {
            return await _pB_ReturnBus.GetReturnSortingDataAsync(Id);
        }

        /// <summary>
        /// PDA回货单保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SavePDAReturnData(PB_ReturnDTO data)
        {
            await _pB_ReturnBus.SavePDAReturnDataAsync(data);
        }

        /// <summary>
        /// 回货单选择收货仓库
        /// </summary>
        /// <param name="deptid">收货方ID</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_Department>> GetReturnWarehouseListData(string deptid)
        {
            return await _pB_ReturnBus.GetReturnWarehouseListDataAsync(deptid);
        }

        /// <summary>
        /// 获取收货人对应的收货单信息
        /// </summary>
        /// <param name="userqecode">人员二维码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<PB_DeliveryNotice>> GetUserReturnData(string userqecode)
        {
            return await _pB_ReturnBus.GetUserReturnDataAsync(userqecode);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_Return data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ReturnBus.AddDataAsync(data);
            }
            else
            {
                await _pB_ReturnBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_ReturnBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}